package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.GradeBean;
import com.project.bean.RoleBean;
import com.project.service.IRoleService;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiresPermissions("role")
@RequestMapping("role")
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @RequestMapping("findAll")
    public List<RoleBean> findAll() {//查询所有角色
        return roleService.findAll();
    }
    @RequestMapping("findByIdArray")
    public List<GradeBean> findByIdArray(int [] gradeArray) {//通过角色id数组查询角色的权限集合，去除重复权限。
        return roleService.findByIdArray(gradeArray);
    }
    @RequestMapping("findAllByPage")
    public IPage<RoleBean> findAllByPage(Integer pageNO) {// 分页查询角色集合
        return roleService.findAllByPage(pageNO);
    }
    @RequestMapping("del")
    public String del(Integer id) {//角色删除
        roleService.del(id);
        return "ok";
    }
    @RequestMapping("findById")
    public RoleBean findById(Integer id) {////按角色id 查询角色信息，同时查询角色拥有的权限集合
        return roleService.findById(id);
    }
    @RequestMapping("findAllGrade")
    public List<GradeBean> findAllGrade() {//查询所有的权限信息
        return roleService.findAllGrade();
    }
    @RequestMapping("updateGrade")
    public String updateGrade(Integer id, int[] newArray) {//修改角色的权限数组
        roleService.updateGrade(id,newArray);
        return "ok";
    }
    @RequestMapping("add")
    public String add(RoleBean roleBean, int[] gradeArray) {//添加角色和角色的权限数组
        roleService.add(roleBean,gradeArray);
        return "ok";
    }
}
